//
//(C) Copyright 2011 HongKong Airline.,Ltd. 
//
/**
 * buycarServiceImpl
 * 项目名称:代购系统
 *
 * @author Mengxiangliang
 *
 * 功能描述:
 * 
 * 历史版本:2013-01-04 v1.0.0 Mengxiangliang  创建:
 * 
 */
 
package com.gamutsoft.amb.buycar.service.impl;

import java.util.List;
import java.util.Map;

import com.gamutsoft.amb.buycar.dao.IBuycarDao;
import com.gamutsoft.amb.buycar.model.Buycar;
import com.gamutsoft.amb.buycar.service.IBuycarService;
import com.gamutsoft.amb.commodity.model.Commodity;
import com.gamutsoft.amb.commodity.service.ICommodityService;
import com.gamutsoft.amb.common.bean.QueryExample;
import com.gamutsoft.amb.common.constants.Constants;
import com.gamutsoft.amb.common.exception.BusinessException;
import com.gamutsoft.amb.common.service.impl.GenericServiceImpl;
import com.gamutsoft.amb.common.util.VDateTime;
import com.gamutsoft.amb.user.model.SystemUser;

public class BuycarServiceImpl extends GenericServiceImpl<Buycar, Long> implements IBuycarService {
	public IBuycarDao buycarDao;
	
	private ICommodityService commodityService;

    public ICommodityService getCommodityService() {
		return commodityService;
	}

	public void setCommodityService(ICommodityService commodityService) {
		this.commodityService = commodityService;
	}

	public BuycarServiceImpl(IBuycarDao buycarDao) {
		super(buycarDao);
		this.buycarDao = buycarDao;
	}
	
	/**
	 * 根据条件查询记录
	 * @author Mengxiangliang
	 * @param  QueryExample
	 * @return BuycarList
	 * @throws BusinessException
	 */
	public List<Map> searchBuycarList(QueryExample qe) throws BusinessException{
	  
	   return buycarDao.searchBuycarList(qe);
	   
	}
	
	/**
	 * 根据ID查询记录
	 * @author Mengxiangliang
	 * @param Long id
	 * @return domain
	 * @throws BusinessException
	 */
	public Buycar searchBuycarById(Long id) throws BusinessException{
	  
	   return buycarDao.searchBuycarById(id);
	   
	}

	/**
	 *  删除记录
	 * @author Mengxiangliang	 
	 * @param id
	 * @throws BusinessException
	 */
	public void deleteBuycarById(Long id) throws BusinessException{
	 
	  buycarDao.deleteBuycarById(id);
	  
	}
	
	/**
	 * 修改记录
	 * @author Mengxiangliang
	 * @param domain
	 * @throws BusinessException
	 */
	public void updateBuycar(Buycar domain) throws BusinessException{
	
	   buycarDao.save(domain);
	   
	}

	/**
	 * 新增记录
	 * @author Mengxiangliang
	 * @param domain
	 * @return
	 * @throws BusinessException
	 */
	public void createBuycar(Buycar domain) throws BusinessException{
	
	   buycarDao.save(domain);
	}

	@Override
	public void createBuyCarByGood(Commodity domain,SystemUser systemUser) throws BusinessException {
		if(domain!=null){
			//创建商品
			domain.setCreateTime(VDateTime.getCurrentStandardTime());
			Commodity bean=commodityService.save(domain);
			//创建购物车
			Buycar buyCar=new Buycar();
			buyCar.setAdddate(VDateTime.getCurrentStandardTime());
			buyCar.setCommodityId(bean.getId());
			buyCar.setStatus(Constants.STATE_VALID);
			buyCar.setUserId(systemUser.getId());
			buycarDao.save(buyCar);
		}
		
		
	}

	@Override
	public List<Map> searchGoodByUserId(Buycar domain) throws BusinessException {
		// TODO Auto-generated method stub
		return buycarDao.searchGoodByUserId(domain);
	}
	

}